package com.itboye.mengwu.app.ui.aizhiwu;

import java.util.Observable;
import java.util.Observer;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.utils.XImageLoader;
import com.itboye.inageview.RoundImageView;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.adapter.ChaKanGengDuoPingLunAdapter;
import com.itboye.mengwu.data.model.HuiFuDetailModel;
import com.itboye.mengwu.data.model.TieZiBaoHanReply.GetAList.ReplyInfo;
import com.itboye.mengwu.data.presenter.TieZiPresenter;
import com.itboye.mengwu.widget.XListView;

public class PingLunAndHuiFuDetailActivity extends BaseActivity implements
		Observer {

	XListView xlistview;
	ImageView back;
	ReplyInfo.ReContent comments;
	String pid, tid, fid;
	TieZiPresenter presenter;
	private HuiFuDetailModel detailModel;
	View headerView;
	RoundImageView head;
	TextView txt_name, txt_time, txt_content;
	private ChaKanGengDuoPingLunAdapter adapter;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.viewmorecomment;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		headerView = LayoutInflater.from(this).inflate(
				R.layout.header_commentdetail, null);
		txt_name = (TextView) headerView.findViewById(R.id.txt_name);
		txt_time = (TextView) headerView.findViewById(R.id.txt_time);
		txt_content = (TextView) headerView.findViewById(R.id.txt_content);
		head = (RoundImageView) headerView.findViewById(R.id.head);
		pid = getIntent().getStringExtra("pid");
		fid = getIntent().getStringExtra("fid");
		tid = getIntent().getStringExtra("tid");
		presenter = new TieZiPresenter(this);
		presenter.getHuiFuDetail(fid, tid, pid);

		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		xlistview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == TieZiPresenter.HuiFuXiangQingDetailSuccess) {
				detailModel = (HuiFuDetailModel) entity.getData();
				txt_name.setText(detailModel.getauthor());
				txt_time.setText(detailModel.getDatelineShow());
				txt_content.setText(detailModel.getComment());
				XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
						+ detailModel.getHead(), head);
				xlistview.removeHeaderView(headerView);
				xlistview.addHeaderView(headerView);
				adapter = new ChaKanGengDuoPingLunAdapter("7", detailModel);
				xlistview.setAdapter(adapter);
			} else if (entity.getEventType() == TieZiPresenter.HuiFuXiangQingDetailFail) {
				ByAlert.alert(entity.getData() + "");
			}
		}
	}

}
